Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

258
Visualizações
import() use static string work well but string variable not work.And throwing error "Error: Cannot find module 'xxx module path'"

Using static import mode works well.For example:

import App from './App.js';

And in common general style of using "import()" works well:

async function fun(){
    const App = async ()=> await import("./App.js");
    console.log(await App() )//it load module successfully
}
fun();

When i use a string variable parameter for import(),it dosn't work.And it will throw error:

async function fun(){
    const path = "./App.js";
    const App = async ()=> await import(path).catch(err=>console.log(err));
    await App() //Error: Cannot find module 'xxx module path'
}
fun();

So,i must load all modules before using.Could i dynamic import modules like that demo?

I go through the mdn docs about dynamic import but not get helpful information.

And require() performs the same.

Does someone have the same questions?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to use ./ and not ../, as ../ is the parent directory and not the current directory. I don't know why this only applies to dynamic imports, but thats just some weird thing about it.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda